package org.gd.hellojaxb.other;

import org.gd.hellojaxb.utils.Marshall;
import org.gd.hellojaxb.utils.MarshallProperties;

import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@XmlType(name = "categoryType")
@XmlRootElement
public class CategoryType {

    @XmlElement(required = true)
    protected String term = "term";

    @XmlElement
    @XmlSchemaType(name = "anyURI")
    protected String scheme = "scheme";

    @XmlElement
    protected String label = "label";

    @XmlElement(namespace = "http://www.w3.org/XML/1998/namespace")
    @XmlSchemaType(name = "anyURI")
    protected String base = "base";

    @XmlElement(namespace = "http://www.w3.org/XML/1998/namespace")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlSchemaType(name = "language")
    protected String lang = "lang";

    @XmlAnyAttribute
    private Map<QName, String> otherAttributes = new HashMap<QName, String>() {{
        put(new QName("QName1"), "QName1");
        put(new QName("QName2"), "QName2");
        put(new QName("QName3"), "QName3");
    }};

    public static void main(String...a) throws JAXBException, IOException {
        System.out.println(
                Marshall.getInstance().marshal(
                        new CategoryType(),
                        MarshallProperties.FORMATTED_OUTPUT
                )
        );
    }
}
